package com.logos.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class ProjectAdvice {

    /**
     * 匹配业务层的所有方法
     */
    @Pointcut("execution(* com.logos.service.*Service.*(..))")
    private void servicePt() {
    }

    @Around("servicePt()")
    public Object runSpeed(ProceedingJoinPoint pjp) throws Throwable {
        Signature signature = pjp.getSignature();
        String signatureName = signature.getName();
        String className = signature.getDeclaringTypeName();
        long start = System.currentTimeMillis();
//        for (int i = 0; i < 1000; i++) {
//            pjp.proceed();
//        }
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        System.out.println(className + "." + signatureName + "====>costTime:" + (end - start));
        return result;
    }
}
